import { createVuePlugin } from 'vite-plugin-vue2'
import Components from 'unplugin-vue-components/vite'
import { ElementUiResolver } from 'unplugin-vue-components/resolvers'
import path from 'path'
import eslintPlugin from '@nabla/vite-plugin-eslint'
import OptimizationPersist from 'vite-plugin-optimize-persist'
import PkgConfig from 'vite-plugin-package-config'

export default {
  plugins: [
    createVuePlugin(/* options */),
    Components({
      resolvers: [ElementUiResolver({ importStyle: 'sass' })],
    }),
    eslintPlugin({ eslintOptions: { cache: false } }),
    PkgConfig(),
    OptimizationPersist(),
  ],
  css: {
    // 🔥此处添加全局scss🔥
    preprocessorOptions: {
      scss: {
        // 避免出现: build时的 @charset 必须在第一行的警告
        charset: false,
        additionalData: '@use "@/assets/scss/_var.scss" as *;',
      },
    },
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
      components: path.resolve(__dirname, 'src/components'),
      layouts: path.resolve(__dirname, 'src/layouts'),
      pages: path.resolve(__dirname, 'src/pages'),
      utils: path.resolve(__dirname, 'src/utils'),
      assets: path.resolve(__dirname, 'src/assets'),
      store: path.resolve(__dirname, 'src/store'),
    },
  },
}
